package com.link.base.base.consumer.controller;

import com.link.base.base.consumer.model.PortalAccntTagItem;
import com.link.base.base.consumer.service.PortalAccntTagItemService;
import com.link.core.basic.annotations.JsonParam;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import com.link.core.cllog.LCLogger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 客户子标签相关服务
 * @author yipeng.zhu@hand-china.com
 * @version 1.0
 * @date: 2018/11/2 15:45
 */

@Controller
@RequestMapping("/link/accntTagItem")
public class AccntTagItemController extends BasicController<PortalAccntTagItem> {
    @Resource
    private PortalAccntTagItemService portalAccntTagItemService;

    @Override
    public BasicService<PortalAccntTagItem> getBasicService() throws Exception {
        return portalAccntTagItemService;
    }

    @Override
    public void beforQueryExample(PortalAccntTagItem entity, HttpServletRequest request) throws Exception {

        entity.setDataSource("CRM");
    }

    /**
     * 标签生效
     *
     * @return
     * @throws
     * @author yipeng.zhu@hand-china.com
     * @date 2018/11/2 16:42
     * @version 1.0
     */

    @RequestMapping(value = "/itemTagApproveUpdate", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> groupTagApproveUpdate(@JsonParam PortalAccntTagItem record, HttpSession session,
                                                     HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>(4);
        try {
            portalAccntTagItemService.itemTagApproveUpdate(record);
            result.put("newRow", portalAccntTagItemService.queryById(record));
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }

    /**
     * 标签失效
     *
     * @return
     * @throws
     * @author yipeng.zhu@hand-china.com
     * @date 2018/11/2 16:43
     * @version 1.0
     */

    @RequestMapping(value = "/itemTagRejectUpdate", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> groupTagRejectUpdate(@JsonParam PortalAccntTagItem record, HttpSession session,
                                                    HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>(4);
        try {
            portalAccntTagItemService.itemTagRejectUpdate(record);
            result.put("newRow", portalAccntTagItemService.queryById(record));
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }

    /**
     * 批量删除行标签
     *
     * @param list 标签行list
     * @return
     * @throws
     * @author yipeng.zhu@hand-china.com
     * @date 2019/1/21 18:55
     * @version 1.0
     */
    @RequestMapping(value = "/batchDelete", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> batchDelete(@RequestBody List<PortalAccntTagItem> list, HttpSession session,
                                           HttpServletRequest request, HttpServletResponse response) {
        HashMap result = new HashMap(16);
        try {
            PortalAccntTagItem entity = null;
            for (int i = 0; list != null && i < list.size(); ++i) {
                entity = list.get(i);
                entity.setValidFlag("N");
                entity.setRow_status("UPDATE");
                portalAccntTagItemService.upsert(entity);
            }
            result.put("success", true);
        } catch (Exception var9) {
            LCLogger.withException(var9);
            result.put("success", false);
            result.put("result", var9.getMessage());
        }
        return result;
    }
}
